package ex.tableapi;

import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.Table;

import static org.apache.flink.table.api.Expressions.row;

public class ExFromValues extends ApiFrame {
    private String outName = "printOutTable";

    public static void main(String[] args) {
        ExFromValues demo = new ExFromValues();
        demo.getEnv();
        Table result = demo.exFromValues();

        demo.registerConsole(demo.createPrintOutDDL(result.getResolvedSchema().toString()), demo.outName);
        result.executeInsert(demo.outName);
    }

    private Table exFromValues() {
        Table table = tEnv.fromValues(
                row(1, "ABC"),
                row(2L, "ABCDE")
        );

        Table table2 = tEnv.fromValues(
                DataTypes.ROW(
                        DataTypes.FIELD("id", DataTypes.DECIMAL(10, 2)),
                        DataTypes.FIELD("name", DataTypes.STRING())
                ),
                row(1, "ABC"),
                row(2L, "ABCDE")
        );
        return table;
    }
}
